-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(redis): added redis option for rate limiter, 10x speed improvement in rate limit checks & reduction of DB load #2263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nt in rate limit checks & reduction of DB load
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryImplemented Redis-based rate limiting with atomic Lua script operations, achieving 10x performance improvement over the DB-only approach. The implementation includes graceful fallback to database when Redis is unavailable, ensuring no disruption for self-hosters. Key improvements:
Architecture:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant API as API Route/Middleware
participant RL as RateLimiter
participant Redis as Redis Client
participant DB as Database
Client->>API: API Request
API->>RL: checkRateLimitWithSubscription()
alt Manual Trigger
RL->>API: allowed=true (bypass)
else API/Webhook/Schedule Trigger
RL->>Redis: getRedisClient()
alt Redis Available
Redis-->>RL: Redis instance
RL->>Redis: eval(Lua: INCR + EXPIRE)
Redis-->>RL: count
alt count <= limit
RL->>API: allowed=true, remaining
else count > limit
RL->>API: allowed=false, remaining=0
end
else Redis Unavailable/Error
Redis-->>RL: null or error
RL->>DB: SELECT rate limit record
alt Record Expired/Missing
RL->>DB: INSERT with onConflictDoUpdate
DB-->>RL: new count
else Record Valid
RL->>DB: UPDATE (atomic increment)
DB-->>RL: updated count
end
alt count <= limit
RL->>API: allowed=true, remaining
else count > limit
RL->>DB: UPDATE isRateLimited=true
RL->>API: allowed=false, remaining=0
end
end
end
API->>Client: Response
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 1 comment
010490c to
14f9190
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 files reviewed, no comments
Summary
Type of Change
Testing
Tested manually
Checklist